class {{classname}} {
  {{#vars}}
  {{#description}}/* {{{description}}} */{{/description}}
  {{{dataType}}} {{name}} = {{{defaultValue}}};
  {{#allowableValues}}
  {{#min}} // range from {{min}} to {{max}}{{/min}}//{{^min}}enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };{{/min}}{
  {{/allowableValues}}
  {{/vars}}
  {{classname}}();

  @override
  String toString() {
    return '{{classname}}[{{#vars}}{{name}}=${{name}}, {{/vars}}]';
  }

  {{classname}}.fromJson(Map<String, dynamic> json) {
    if (json == null) return;
  {{#vars}}
  {{#isDateTime}}
    {{name}} = (json['{{baseName}}'] == null) ?
      null :
      DateTime.parse(json['{{baseName}}']);
  {{/isDateTime}}
  {{#isDate}}
    {{name}} = (json['{{baseName}}'] == null) ?
      null :
      DateTime.parse(json['{{baseName}}']);
  {{/isDate}}
  {{^isDateTime}}
  {{^isDate}}
    {{#complexType}}
      {{#isListContainer}}
    {{name}} = (json['{{baseName}}'] == null) ?
      null :
      {{complexType}}.listFromJson(json['{{baseName}}']);
      {{/isListContainer}}
      {{^isListContainer}}
      {{#isMapContainer}}
      {{#items.isListContainer}}
    {{name}} = (json['{{baseName}}'] == null) ?
      null :
      {{items.complexType}}.mapListFromJson(json['{{baseName}}']);
      {{/items.isListContainer}}
      {{^items.isListContainer}}
    {{name}} = (json['{{baseName}}'] == null) ?
      null :
      {{complexType}}.mapFromJson(json['{{baseName}}']);
      {{/items.isListContainer}}
      {{/isMapContainer}}
      {{^isMapContainer}}
    {{name}} = (json['{{baseName}}'] == null) ?
      null :
      {{complexType}}.fromJson(json['{{baseName}}']);
      {{/isMapContainer}}
      {{/isListContainer}}
    {{/complexType}}
    {{^complexType}}
      {{#isListContainer}}
    {{name}} = (json['{{baseName}}'] == null) ?
      null :
      (json['{{baseName}}'] as List).cast<{{items.datatype}}>();
      {{/isListContainer}}
      {{^isListContainer}}
        {{#isMapContainer}}
    {{name}} = (json['{{baseName}}'] == null) ?
      null :
      (json['{{baseName}}'] as Map).cast<String, {{items.datatype}}>();
        {{/isMapContainer}}
        {{^isMapContainer}}
          {{#isDouble}}
    {{name}} = (json['{{baseName}}'] == null) ?
      null :
      json['{{baseName}}'].toDouble();
          {{/isDouble}}
          {{^isDouble}}
    {{name}} = json['{{baseName}}'];
          {{/isDouble}}
        {{/isMapContainer}}
      {{/isListContainer}}
    {{/complexType}}
  {{/isDate}}
  {{/isDateTime}}
  {{/vars}}
  }

  Map<String, dynamic> toJson() {
    Map <String, dynamic> json = {};
    {{#vars}}
        {{^isNullable}}
    if ({{name}} != null)
        {{/isNullable}}
        {{#isDateTime}}
      json['{{baseName}}'] = {{name}} == null ? null : {{name}}.toUtc().toIso8601String();
      {{/isDateTime}}
      {{#isDate}}
      json['{{baseName}}'] = {{name}} == null ? null : {{name}}.toUtc().toIso8601String();
      {{/isDate}}
      {{^isDateTime}}
      {{^isDate}}
      json['{{baseName}}'] = {{name}};
      {{/isDate}}
      {{/isDateTime}}
    {{/vars}}
    return json;
  }

  static List<{{classname}}> listFromJson(List<dynamic> json) {
    return json == null ? List<{{classname}}>() : json.map((value) => {{classname}}.fromJson(value)).toList();
  }

  static Map<String, {{classname}}> mapFromJson(Map<String, dynamic> json) {
    var map = Map<String, {{classname}}>();
    if (json != null && json.isNotEmpty) {
      json.forEach((String key, dynamic value) => map[key] = {{classname}}.fromJson(value));
    }
    return map;
  }

  // maps a json object with a list of {{classname}}-objects as value to a dart map
  static Map<String, List<{{classname}}>> mapListFromJson(Map<String, dynamic> json) {
    var map = Map<String, List<{{classname}}>>();
     if (json != null && json.isNotEmpty) {
       json.forEach((String key, dynamic value) {
         map[key] = {{classname}}.listFromJson(value);
       });
     }
     return map;
  }
}
